<!DOCTYPE html>
<html lang="en" class="no-js">
<head>
    <meta charset="utf-8"/>
    <title>北京远大都管理中心</title>
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta name="description" content="">
    <meta name="author" content="">

    <link rel="stylesheet" media="screen" href="css/login/login.css">
    <link rel="stylesheet" href="./layer/theme/default/layerui.css">
    <!-- HTML5 shim, for IE6-8 support of HTML5 elements -->
    <!--[if lt IE 9]>
    <script src="http://html5shim.googlecode.com/svn/trunk/html5.js"></script>
    <![endif]-->
</head>
<body>
<!-- particles.js container -->
<div id="particles-js" style="display: flex;align-items: center;justify-content: center">
    <canvas class="particles-js-canvas-el" style="width: 100%; height: 100%;" width="472" height="625"></canvas>
</div>
<div class="apTitle">学生后台管理系统</div>
<div class="logcon">
    <input type="text" name="username" placeholder="账号">
    <input type="password" name="password" placeholder="密码">
    <button type="button" id="submit">登录</button>
</div>
<!-- scripts -->
<script src="js/login/login.js"></script>
<script src="js/login/loginApp.js"></script>
<!--<script>
    function changeImg() {
        let pic = document.getElementById('picture');
        console.log(pic.src)
        if (pic.getAttribute("src", 2) == "images/login/check.png") {
            pic.src = "images/login/checked.png"
        } else {
            pic.src = "images/login/check.png"
        }
    }
</script>-->
<!-- Javascript -->
<script src="js/jquery.js"></script>
<script src="./layer/layer.js"></script>
<script src="js/md5.js"></script>
<script src="js/commit.js"></script>
<script>
    // md5($("input[name=password]").val())
    var u = $("input[name=username]");
    var p = $("input[name=password]");
    $("#submit").on('click', function () {
        if (u.val() == '' || p.val() == '') {
            layer.msg('用户名或密码不能为空');
            return false;
        } else {
            var reg = /^[0-9A-Za-z]+$/;
            if (!reg.exec(u.val())) {
                layer.msg('用户名错误');
                return false;
            }
        }
        $.ajax({
            url: 'https://practice-api.bjjixin.cn/backend/v1/user/login',
            type: 'POST',
            dataType: 'json',
            data: {
                username: $("input[name=username]").val(),
                password: $("input[name=password]").val()
            }
        }).done(function (data) {
            admin.tooken = data.access_token
            if (admin.tooken) {
                admin.setCookierl("istooken", true, 1, "/");
                admin.setCookierl("cookval", admin.tooken, 1, "/");
                admin.setCookierl("token_type", data.token_type, 1, "/");
            }
            admin.ajaxFn(
                {
                    url: admin.baseUrl.loginuser,
                    type: 'POST',
                    data: {}
                },
                function (res) {
                    console.log(res)
                    admin.setCookierl("usertxt", res.username, 1, "/");
                    window.open('/index.html', '_self');
                }
            )
        }).error(function (XHR, textStatus, errorThrown) {
            if (XHR.status === 400) {
                let responseJSON = jQuery.parseJSON(XHR.responseText);
                if (responseJSON.code === 40000) {
                    //TODO 提示框
                    layer.msg(responseJSON.message);
                }
            }
        });
    });
</script>
</body>
</html>


